package wxwork

import (
	"github.com/ArtisanCloud/PowerWeChat/v3/src/work"
	"github.com/ArtisanCloud/PowerWeChat/v3/src/work/message/request"
	"github.com/gin-gonic/gin"
	"lianzi_gos/internal/config"
)

func SendWorkMessage(c *gin.Context, userID, content string) (interface{}, error) {
	agentid := config.C.WechatWork.AgentID
	corpid := config.C.WechatWork.CorpID
	secret := config.C.WechatWork.Secret

	WeComApp, err := work.NewWork(&work.UserConfig{
		CorpID:  corpid,  // 企业微信的app id，所有企业微信共用一个。
		AgentID: agentid, // 内部应用的app id
		Secret:  secret,  // 内部应用的app secret
		OAuth: work.OAuth{
			Callback: "https://wecom.artisan-cloud.com/callback",
			Scopes:   nil,
		},
		HttpDebug: true,
	})
	if err != nil {
		panic(err)
	}

	messages := &request.RequestMessageSendText{
		RequestMessageSend: request.RequestMessageSend{
			ToUser: userID,
			//ToParty:                "1",
			//ToTag:                  "",
			MsgType:                "text",
			AgentID:                agentid,
			Safe:                   0,
			EnableIDTrans:          0,
			EnableDuplicateCheck:   0,
			DuplicateCheckInterval: 1800,
		},
		Text: &request.RequestText{
			Content: content,
		},
	}
	return WeComApp.Message.SendText(c, messages)
}
